Data records in a relational database management system (RDBMS) in a computer are maintained in tables, which are a collection of rows having the same columns. Each column maintains information on a particular type of data for the data records of the rows. Data from the database tables may be accessed using instructions in a language that the database management system recognizes. For example, Structured Query Language (SQL) statements are often used to query, access, and manipulate data in a database.
A SQL statement includes set operators that define operations to be performed by the database management system when searching columns of database tables. For instance, a SQL set operator may look for all records having a field that satisfies a search condition, such as equal to or less than a certain value. Also, the operator can be a join, which combines or concatenates rows from different tables, then searches for those concatenated rows that satisfy a search predicate. Rows from the tables involved in the join operation that do not satisfy the predicate or condition are excluded from the join result.
There are two methods of developing applications which interface with a relational database system. The first is to use static or dynamic SQL statement calls from within the application program. A dynamic SQL statement is constructed by the application program, “prepared” or complied with a call to the database management system, and then executed. A static SQL statement is coded into the application program, and prepared or compiled prior to running the application program.
The second method of developing applications which interface with a relational database system identifies common functions that call one or more SQL statements, and encapsulates each function as a Stored Procedure to be executed at the database server instead of the application, improving performance and in many cases simplifying application development.
When an application program or Stored Procedure is compiled, a separate step is performed to create an access plan for each SQL statement using the operators and search values in the statement to retrieve data in an efficient manner. For a static SQL statement, the access plan is based on the state of the database at the time the plan is generated. The access plan can be recreated using the current state of the database at any time by first updating database statistics and then “re-binding”. Most of the access plans generated by this process are optimal.
However, a few poorly performing statements can consume a significant amount of the database management system resources, resulting in a slowdown of the system. To find statements which use a large amount of CPU or I/O time, an event monitor in the database management system creates an event record of each SQL statement or stored procedure that is executed by the system, to record performance information for the executed statement.
When a SQL statement has a performance problem, such as a high execution time or a high number of rows read, written or sorted, finding the SQL statement with this poor execution performance is generally the first step in correcting the problem. For example, the event records for the executed SQL statements are studied to find the statements having these types of performance problems. However, the event monitor can include records for thousands or millions of executed statements, and each record can contain many lines with performance information for a single SQL statement. As a result, searching this amount of data to locate a problem statement is very time consuming, and is therefore often not done.
If the problem statement is executed infrequently, such as once at start-up, then the overall impact on system performance may be insignificant, and the problem statement can be left in place. However, if the problem statement is executed frequently, and accounts for a significant reduction in system performance, then the problem statement needs to be identified so that its execution performance, and the overall performance of the system, can be improved.
Without a tool to summarize the performance records of the executed statements, identifying the problem statement, and the statement's overall impact on system performance, is very difficult. There is therefore a need for a summary of the performance of SQL statements so that poorly performing statements can be identified.
Furthermore, the event monitor typically includes the text of dynamic SQL statements, but not the text of static SQL statements. For static SQL statements, which are coded into the application program, their preparation or compilation is done prior to running the application program. Therefore, the event monitor contains only the package (or module) name and section number of the SQL statement, which indicates the relative position of the SQL statement within the module, rather than the actual text itself.
As a result, most users who are not familiar with the internal storage used by the database management system often attempt to locate the text of the static SQL statement within the source code of the application program using the package name and section number from the event monitor, but this can be time consuming and error prone. This may also be impossible, if the user does not have access to the application source code. A user may also be able to either use a tool, such as a DB2 control center, or have the ability to query a system table, to find the static SQL statement. However, if the event monitor is from another system, then the user may have to ask a customer to find the text of the static statement.
There is therefore also a need to be able to identify the text of a poorly performing static SQL statement from the performance data so that the statement can be further analyzed and tuned for improved performance.